//***************************************************************** //* NTHU General Physics Laboratory * //* 109.04.01 * //* Code by Tendy Yeh a4100791ex@gmail.com * //* * //* RLC expriment with Snapino, visit * //* http://www.phys.nthu.edu.tw/~gplab/ for more infomation * //***************************************************************** #include //匯入Timer程式庫 Timer timer; //命名Timer物件 long timestamp; //時間標籤變數(x軸) int Signal; //訊號讀取變數(y軸) char c[10], d[6]; //格式化顯示字串變數 void setup() { Serial.begin(2000000); //開啟序列埠通訊 pinMode(10, OUTPUT); //設定D10為輸出腳位 timer.oscillate(10, 20, LOW); //設定方波參數,輸出為D10腳、每20毫秒改變狀態、起始為LOW Serial.println("Time(s)\tSingnal(V)"); } //(使D10產生週期40ms的方波) void loop() { timestamp = micros(); //紀錄時間,單位為微秒 Signal = analogRead(A0); //偵測訊號電壓值,0~5V 對應到 0~1023; dtostrf(timestamp * 0.000001, 3, 6, c); //將時間單位轉換為s,並轉成文字格式 dtostrf(Signal * 0.0048876, 2, 3, d); //將訊號單位轉換為V,並轉成文字格式 Serial.println(String(c) + "\t" + String(d)); //由序列埠輸出資料 timer.update(); //依設定週期改變D10腳位狀態 while (millis() > 300); //時間大於0.3秒後停止偵測 }